<?
    class AdvancedImageViewer extends HTMLControl {
        private $_images;
        private $_initial;
        private $_comments;
        
        function __construct($images, $initial = 0) {
            parent::__construct("div",null,array("class"=>"aimageviewer"));
            
            $this->_images = $images;
            $this->_initial = $initial;
            
            $paths = array();
            foreach ($this->_images as $img) {
                $paths[] = Conf::GetApplicationRoot() . "/$img";
            }
            
            
            $this->AddChild($this->getNavbar());
            $this->AddChild($this->getImagePanel());
            
            $this->AddChild(new HTMLControl("input",null,array("type"=>"hidden","id"=>"aiv_images","value"=>implode(",",$paths))));
            $this->AddChild(new HTMLControl("input",null,array("type"=>"hidden","id"=>"aiv_initial","value"=>$initial)));
        }
        
        function AddComments($comments) {
            $this->_comments = $comments;
            $this->AddChild(new HTMLControl("input",null,array("type"=>"hidden","id"=>"aiv_comments","value"=>implode(",",$this->_comments))));
            
            $this->AddChild($this->getCommentPanel());
        }
        
        private function getNavbar() {
            $prevbutton = new PrevButton();
            $prevbutton->attributes->onclick = "aiv_advance(-1)";
            $prevcell = new HTMLControl("td",$prevbutton,array("class"=>"navbar_left"));
            
            $nextbutton = new NextButton();
            $nextbutton->attributes->onclick = "aiv_advance(1)";
            $nextcell = new HTMLControl("td",$nextbutton,array("class"=>"navbar_right"));
            
            $indicatorcell = new HTMLControl("td",null,array("class"=>"navbar_center"));
            for ($x = 0; $x < count($this->_images); $x++) {
                $cur = new HTMLControl("a","&nbsp;&nbsp;&nbsp;",array("class"=>"indicator","id"=>"indicator_$x"));
                if ($x == $this->_initial)
                    $cur->SetAttribute("class","active indicator");
                    
                $cur->attributes->onClick = "aiv_goto($x)";
                    
                $indicatorcell->AddChild($cur);
            }
            
            $row = new HTMLControl("tr");
            $row->AddChild($prevcell);
            $row->AddChild($indicatorcell);
            $row->AddChild($nextcell);
            
            $table = new HTMLControl("table",$row,array("class"=>"wide navbar"));
            return new HTMLControl("div",$table,array("class"=>"indicatorbar"));
        }
        
        private function getImagePanel() {
            $img = new HTMLControl("img",null,array("id"=>"aiv_image","src"=>$this->_images[$this->_initial]));
            return new HTMLControl("div",$img,array("class"=>"image"));
        }
        
        private function getCommentPanel() {
            return new HTMLControl("div",$this->_comments[$this->_initial],array("class"=>"comment","id"=>"aiv_comment_pane"));
        }
    }
?>